package com.burst.reptile.modular.web.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.burst.reptile.framework.web.controller.BaseController;
import com.burst.reptile.framework.web.result.Result;
import com.burst.reptile.modular.web.entity.ZpBanner;
import com.burst.reptile.modular.web.form.SortForm;
import com.burst.reptile.modular.web.service.IZpBannerService;

import lombok.RequiredArgsConstructor;

/**
 * <p>
 * 轮播图 前端控制器
 * </p>
 *
 * @author wujin
 * @since 2020-07-07
 */
@RestController
@RequestMapping("/web/banner")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class ZpBannerController extends BaseController{
	
	private final IZpBannerService bannerService;

	/**
	 * 轮播图列表
	 * @return
	 */
	@GetMapping("/list")
	@PreAuthorize("@ss.hasPermi('zp:banner:list')")
	public Result<Object> list(){
		return Result.success(bannerService.listAll());
	}
	
	/**
	 * 添加
	 * @return
	 */
	@PostMapping("/add")
	@PreAuthorize("@ss.hasPermi('zp:banner:add')")
	public Result<Object> add(@Validated @RequestBody ZpBanner banner) {
		this.bannerService.add(banner);
		return SUCCESS;
	}
	
	/**
	 * 编辑
	 * @return
	 */
	@PutMapping("/edit")
	@PreAuthorize("@ss.hasPermi('zp:banner:edit')")
	public Result<Object> edit(@Validated @RequestBody ZpBanner banner) {
		this.bannerService.edit(banner);
		return SUCCESS;
	}
	
	/**
	 * 编辑状态
	 * @return
	 */
	@PutMapping("/changeStatus")
	@PreAuthorize("@ss.hasPermi('zp:banner:edit')")
	public Result<Object> changeStatus(@RequestBody ZpBanner banner) {
		this.bannerService.changeStatus(banner);
		return SUCCESS;
	}
	
	/**
	 * 删除
	 * @param id
	 * @return
	 */
	@DeleteMapping("/remove/{id}")
	@PreAuthorize("@ss.hasPermi('zp:banner:remove')")
	public Object remove(@PathVariable String id) {
		this.bannerService.delete(id);
		return SUCCESS;
	}
	
	/**
	 * 排序
	 * @param id ID
	 * @param sort 排序号
	 * @return
	 */
	@PutMapping("/sort")
	@PreAuthorize("@ss.hasPermi('zp:banner:sort')")
	public Object sort(@Validated @RequestBody SortForm sort) {
		this.bannerService.sort(sort);
		return SUCCESS;
	}
	
}
